from Products.Five.browser import BrowserView
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
import random
class Tab(object):
    pass
class FrontPageView(BrowserView):
    template = ViewPageTemplateFile('tp/frontpage.html')

    def __call__(self):
        return self.template()

    def get_tabs(self):
        tabs=[]
        tabs.append({'index':1,'tab':"Noticias",'type':"News Item"})
        tabs.append({'index':2,'tab':"Eventos",'type':"Event"})
        tabs.append({'index':3,'tab':"Foro",'type':"PloneboardConversation"})
        tabs.append({'index':4,'tab':"Blog",'type':"Blog Entry"})
        return tabs
    def get_folder_tabs(self,folder,limit):
        limit=limit
 
        alldocs = self.context.portal_catalog.searchResults(portal_type=(folder),
                                                        sort_on="Date",
                                                        sort_order='reverse',
                                                        sort_limit=limit)[:limit]
        #print folder , ' = ',len(alldocs)
        return alldocs[:limit]

    def get_folder_category(self,folder,category,limit):
        limit=limit

        alldocs = self.context.portal_catalog.searchResults(portal_type=(folder),
                                                        Subject=(category),
                                                        sort_on="Date",
                                                        sort_order='reverse',
                                                        sort_limit=limit)[:limit]
        #print folder , ' = ',len(alldocs)
        return alldocs[:limit]

    def get_events_recents(self,folder,limit):
        limit=limit

        alldocs = self.context.portal_catalog.searchResults(portal_type=(folder),
                                                        sort_on="Date",
                                                        sort_order='reverse',
                                                        sort_limit=limit)[:limit]
        return alldocs[:limit]
    def get_random_link(self,category,limit):
        alldocs = self.context.portal_catalog.searchResults(portal_type=('Link'),
                                                        Subject=(category),
                                                        sort_limit=limit)
        random.shuffle(alldocs)
        return alldocs[:limit]